package com.achang.achangmall.product.web;

import com.achang.achangmall.product.entity.CategoryEntity;
import com.achang.achangmall.product.service.CategoryService;
import com.achang.achangmall.product.vo.Catelog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/******
 @author 阿昌
 @create 2021-10-04 14:35
 *******
 */
@Controller
public class IndexController {

    @Autowired
    private CategoryService categoryService;

    //进入商品首页
    @GetMapping({"/","/index.html"})
    public String indexPage(Model model){
        //查出一级分类
        List<CategoryEntity> categoryEntityList = categoryService.getLevel1Categorys();
        model.addAttribute("categorys",categoryEntityList);
        return "index";
    }

    //index/catalog.json
    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<Long, List<Catelog2Vo>>  getCatalogJson(){
        Map<Long, List<Catelog2Vo>>  resultMap = categoryService.getCatelogJson();
        return resultMap;
    }

    @ResponseBody
    @GetMapping("/hello")
    public String  hello(){
        return "hello";
    }

}
